/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/anagrams
@Language: C++
@Datetime: 16-02-15 05:40
*/

class Solution {    
public:    
    /**
     * @param strs: A list of strings
     * @return: A list of strings
     */
    vector<string> anagrams(vector<string> &strs) {
        // write your code here
		int len = strs.size();        
		unordered_map<string,int> hash;
        for(int i=0;i<len;++i){
			string s=strs[i];
			sort(s.begin(),s.end());
			hash[s]++;
        }

		vector<string> vs;
		for(int i=0;i<len;++i){
			string s=strs[i];
			sort(s.begin(),s.end());
			if(hash[s]>1) vs.push_back(strs[i]);
        }		
        return vs;
    }
};